﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace ToDoList.Logic
{
    public class ManageUser
    {
        //private static todoContext _ctx = new todoContext();

        public bool SignUp(string password, string nickName)
        {
            int id = DataSource.users.Max(a => a.UserID) + 1;
            var user = DataSource.users.SingleOrDefault(a => a.UserID == id);
            if (user == null)
            {
                User NewUser = new User()
                {
                    UserID = id,
                    Password = password,
                    NickName = nickName,
                    mattes = new List<Matter>(),
                    detailedLists = new List<DetailedList>()
                };
                DataSource.users.Add(NewUser);
                return true;
            }
            else
                return false;
        }
        //public void SignUp(string password, string nickName)
        //{
        //    Users user = new Users
        //    {
        //        UserName = nickName,
        //        Password = password
        //    };
        //    _ctx.Users.Add(user);
        //    _ctx.SaveChanges();

        //}

        public bool SignIn(int id, string password)
        {
            var user = DataSource.users.SingleOrDefault(a => a.UserID==id && a.Password.Equals(password));
            if (user != null)
            {
                return true;
            }
            else
                return false;
        }
    }

}
